package com.sands.network.apihelper;

import android.content.Context;

import com.google.gson.Gson;
import com.sands.app.App;
import com.sands.network.module.CacheConfig;
import com.sands.network.module.UserToken;
import com.sands.network.util.ACache;


/**
 * Created by kunqi.lai on 2016/8/24 18:09.
 * email :781548819@qq.com
 */
public class BaseApiHelper {
    public static Gson mGson;
    static Context mContext;
    static ACache mACache;

    static {
        mGson = new Gson();
        mContext = App.getInstance().getApplicationContext();
        mACache = ACache.get(mContext);
        //获取token的操作，考虑在api方法获取当前最新token
    }

    /**
     * 获取token
     *
     * @return
     */
    public static String token() {
        String json = mACache.getAsString(CacheConfig.Key_User_Token);
        UserToken userToken = mGson.fromJson(json,UserToken.class);
       return userToken == null ? "82055bd82e5baa1150a073fcbb739d9ddbe1dd63" : userToken.getAccess_token();

    }
}
